GetFolder Method (Session Object) 

The GetFolder method returns a Folder object from a MAPI message store.

Syntax

Set objFolder = objSession.GetFolder(folderID [, storeID] )

Parameters

objFolder

On successful return, contains the Folder object with the specified identifier. When the folder does not exist, GetFolder returns Nothing.

objSession

Required. The Session object.

folderID

Required. String that specifies the unique identifier of the folder. When you provide an empty string, some providers return the root folder. See the remarks for more information.

storeID

Optional. String that specifies the unique identifier of the message store. The default value is an empty string, which corresponds to the default message store.

 

Remarks

The GetFolder method allows you to obtain any folder for which you know the identifier.

For some message stores, you can also obtain the root folder by supplying an empty string as the value for folderID. When the message store does not support returning the root folder, the call returns the error value MAPI_E_NOT_FOUND.

The root folder is the parent of the folder that represents the IPM subtree. The IPM subtree is the hierarchy of folders for all messages whose message class starts with IPM, such as IPM.Note.

Note that the root folder differs from the IPM root folder. You can obtain the IPM root folder with the InfoStores object s RootFolder property, or when you use the Parent property to trace up through the hierarchy of folders. You can only obtain the root folder by calling GetFolder with the empty string supplied for the folderID parameter.

Example

The following example uses the GetFolder method to obtain a specific folder from a MAPI message store:

' from the function Session_GetFolder

' requires a global variable that contains the folder ID

' uses a global variable that contains the message store ID if present

    If strFolderID = "" Then

        MsgBox ("Must first set folder ID variable; see Folder->ID")

        Exit Function

    End If

    If strFolderStoreID = "" Then ' if it's not there, don't use it

        Set objFolder = objSession.GetFolder(strFolderID)

    Else

        Set objFolder = objSession.GetFolder(folderID:=strFolderID, _

                                    storeID:=strFolderStoreID)

    End If

    If objFolder Is Nothing Then

        Set objMessages = Nothing

        MsgBox "Unable to retrieve folder with specified ID"

        Exit Function

    End If

    MsgBox "Folder set to " & objFolder.Name

    Set objMessages = objFolder.Messages

 

See Also

Folder ObjectKM47H0

ID Property (Folder Object)Y080V6